<?php

namespace app\admin\model\kuerp;

use think\Model;
use traits\model\SoftDelete;

class SaleGoals extends Model
{

    use SoftDelete;
    // 表名
    protected $name = 'kuerp_sale_goals';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    const CONTRACT_TYPE = 1;//订单
    const COLLECTION_TYPE = 2;//回款
    const CUSTOMER_TYPE = 3;//客户
    const SIGNIN_TYPE = 4;//拜访
    const FOLLOW_TYPE = 5;//跟进

    // 追加属性
    protected $append = [
        'status_text',
        'model_class_text',
    ];
    protected $type = [
        'model_class' => 'integer'
    ];
    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }
    
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getModelClassList()
    {
        return [ 
            self::CONTRACT_TYPE   => __('订单'), 
            self::COLLECTION_TYPE => __('回款'),
            self::CUSTOMER_TYPE   => __('客户'),
            self::SIGNIN_TYPE     => __('拜访'),
            self::FOLLOW_TYPE     => __('跟进'),
        ];
    }

    public function getModelClassTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['model_class']) ? $data['model_class'] : '');
        $list = $this->getModelClassList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getYearsAttr($value)
    {
        return explode(',', $value);
    }
    public function setYearsAttr($value)
    {
        return implode(',', $value);
    }






}
